package src.Fourteen;

import javax.swing.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class WindowListener_Example extends JFrame {

    public static void main(String[] args) {
        WindowListener_Example example = new WindowListener_Example();
        example.setVisible(true);
    }

    public WindowListener_Example(){
        super();
        addWindowListener(new MyWindowListener());
        setTitle("捕获其他窗体");
        setBounds(100,100,500,375);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    private class MyWindowListener implements WindowListener{

        @Override
        public void windowOpened(WindowEvent e) {
            System.out.println("窗口被打开");
        }

        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println("窗口将要关闭");
        }

        @Override
        public void windowClosed(WindowEvent e) {
            System.out.println("窗口被关闭");
        }

        @Override
        public void windowIconified(WindowEvent e) {
            System.out.println("窗口被图标化");
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
            System.out.println("窗口被非图标化");
        }

        @Override
        public void windowActivated(WindowEvent e) {
            System.out.println("窗口被激活");
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
            System.out.println("窗口不再处于激活状态");
        }
    }
}
